/*
 *  Eight Queens Puzzle
 */

/*-------- Includes --------*/
#include <stdio.h>
#include <stdlib.h>

/*-------- Global variables --------*/
int count = 0;

/*-------- Punction prototypes --------*/
void dfs(int *data, int step);
void display(int *data);

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int chess[8];

    dfs(chess, 0);

    printf("count = %d\n", count);

    return 0;
}

/*-------- Functions --------*/
void dfs(int *data, int step)
{
    // base case
    if (step == 8) { count++; display(data); return; }

    for (int i = 0; i < 8; i++) {
        int j;
        for (j = 0; j < step; j++) {
            // column conflict
            if (data[j] == i) break;

            // diagonal conflict
            if (data[j] == i + step - j) break;

            if (data[j] == i - step + j) break;
        }

        if (j < step) continue; // position i is conflict

        data[step] = i;
        dfs(data, step + 1);
    }
}

void display(int *data)
{
    for (int i = 0; i < 8; i++) {
        int k = data[i];

        for (int j = 0; j < 8; j++)
            if (k == j) putchar('+');
            else        putchar('-');

        putchar('\n');
    }

    putchar('\n');
}
